#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define R register
#define L long
#define LL long long
#define I inline
#define U unsigned

I LL read()
{
	R LL x;R char f;R char c;
	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');
	for (x=c-'0'; (c=getchar())>='0'&&c<='9'; x=(x<<3)+(x<<1)+c-'0');
	return f?-x:x;
}
struct shu
{
    char ming[100];
    double qian;
};
struct shu shus[1000];



int main()
{
    int n=read(),maxi=0,mini=0;
    for(int i=0;i<n;++i)
    {
        int l=0;
        for(char c;(c=getchar())!='\n';shus[i].ming[l]=c,++l);
        shus[i].ming[l]=0;
        scanf("%lf\n",&shus[i].qian);
        if(shus[i].qian>shus[maxi].qian)maxi=i;
        if(shus[i].qian<shus[mini].qian)mini=i;
    }
    printf("%.2lf, %s\n",shus[maxi].qian,shus[maxi].ming);
    printf("%.2lf, %s\n",shus[mini].qian,shus[mini].ming);
 	return 0;
}
